csofandomcom-20200223-history
Studio (mode)/Lua
This is some tutorials and available scripts for Lua function in Studio (mode). FAQs Q1: How do I know a block's coordinate? You can see a block's coordinate by pressing V+3 in Studio Creation mode. =game.lua= Change the player's numerical value *Change the player's value with the button. button1 = Game.EntityBlock.Create({x=-42, y=-24, z=2}) function button1:OnUse(player) if self.onoff true then player.health = 10 player.armor = 10 else player.health = 100 player.armor = 100 end end Analysis: *Row 1: "button1" is the name created for a lever device block at coordinate x=-42, y=-24, z=2. *Row 2: The lever can be used by the player. *Row 3-5: If the lever is turned on, the player health and armor will become 10. *Row 6-8: If the level is turned off, the player health and armor will become 100. Chat Events *Open door with signal from player. SIGNAL = { TRIGGER1 = 1 } trigger2 = Game.EntityBlock.Create({x=-42, y=-31, z=2}) door2 = Game.EntityBlock.Create({x=-42, y=-35, z=1}) function Game.Rule:OnPlayerSignal(player, signal) -- start if signal SIGNAL.TRIGGER1 then trigger2:Event({action="use"}, 0) end end Analysis: *Row 1: The signal is from "TRIGGER1 = 1" (From ui.lua) *Row 2: A new name is created that is "trigger2". It is a button. *Row 3: A door is named as "door2". *Row 4-6: If a player types "start" in chat, the door will open. *Row 7: If the player tried to open the door with E button, it is futile. UI Display *Create and modify UI elements for players sync1 = Game.SyncValue.Create("sync1") button3_1 = Game.EntityBlock.Create({x=-45, y=-40, z=1}) function button3_1:OnUse(player) sync1.value = "1x" end button3_2 = Game.EntityBlock.Create({x=-45, y=-39, z=1}) function button3_2:OnUse(player) sync1.value = "2x" end button3_3 = Game.EntityBlock.Create({x=-45, y=-38, z=1}) function button3_3:OnUse(player) sync1.value = "3x" end Analysis: *Row 1-5: If a player press a button named as "button3_1", a "1x" text will appear on player screen. *Row 6-9: If a player press a button named as "button3_2", a "2x" text will appear on player screen. *Row 10-13: If a player press a button named as "button3_3", a "3x" text will appear on player screen. Special device block *Some device blocks receive special events. textboard = Game.EntityBlock.Create({x=-42, y=-48, z=2}) trigger4_1 = Game.EntityBlock.Create({x=-42, y=-47, z=1}) function trigger4_1:OnUse(player) textboard:Event({action="text", value="Hello"}) end trigger4_2 = Game.EntityBlock.Create({x=-43, y=-47, z=1}) function trigger4_2:OnUse(player) textboard:Event({action="text", value="World"}) end Analysis: *Row 1-5: When a button named as "trigger4_1" is pressed, a text board named as "textboard" will appear "Hello" on its board. *Row 6-9: When a button named as "trigger4_2" is pressed, a text board named as "textboard" will appear "World" on its board. Scripted Victory *Use coins and scripts to satisfy victory conditions. switch5 = Game.EntityBlock.Create({x=-52, y=-46, z=2}) function switch5:OnUse(player) if player.coin >= 2000 then player:Win() end end Analysis: *Row 1: A switch is named as "switch 5". *Row 2: If the switch is flipped by the player, *Row 3: AND the player has more than 2000 coins *Row 4: The player name will appear and win the game. The game ends in several seconds. =ui.lua= Room 2 Chat Event SIGNAL = { TRIGGER1 = 1 } function UI.Event:OnChat(msg) if string.find(msg, "start") then UI.Signal(SIGNAL.TRIGGER1) end end Analysis: The signal is active when a object named as "trigger1" is activated which is after the player typed "start" in the chat. Room 3 UI labelBG = UI.Box.Create() labelBG:Set({x=50, y=50, width=100, height=100, r=50, g=50, b=50, a=200}) labelBG:Hide() label = UI.Text.Create() label:Set({font="large", align="center", x=50, y=50, width=100, height=100, r=255, g=255, b=255}) label:Hide() sync1 = UI.SyncValue.Create("sync1") function sync1:OnSync() labelBG:Show() label:Show() label:Set({text = self.value}) end Analysis: *Row 1: The background of the label is created and named as "labelBG". *Row 2: The position, width, height and color of the label is set. *Row 3: The initial label is hidden until activated. *Row 7-11: The label will show itself when activated. External links *www.lua.org Lua Official Website *Some examples of Lua Script that can be used in fashion studios *Megaxus Studio Mode Lua Script Example Category:Modes